package com.atguigu.service.impl;

import com.atguigu.entity.Article;
import com.atguigu.entity.Comment;
import com.atguigu.entity.User;
import com.atguigu.feign.CommentFeignClient;
import com.atguigu.feign.UserFeignClient;
import com.atguigu.mapper.ArticleMapper;
import com.atguigu.service.ArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper,Article> implements ArticleService {


    @Autowired
    private UserFeignClient userFeignClient;
    @Autowired
    private CommentFeignClient commentFeignClient;

    @Override
    public Article getArticleUserAndCommentById(Integer articleId) {
        Article article = getById(articleId);
        if (article == null) return null;
        User user = userFeignClient.getUser(article.getUserId());
        List<Comment> commentList = commentFeignClient.queryCommentList(articleId);
        article.setUser(user);
        article.setCommentList(commentList);
        return article;
    }
}
